package trucaso;
/*
 * 	This is the frame's menu
 */
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;

public class MenuBar extends JMenuBar {
	JMenu game,options,help,newGame,onlineGame,onlineGameHelp;
	JMenuItem quit,about,cardValues,background,localGame,create,join,changeName,serverHelp,clientHelp;
	JFrame superFrame;
	
	protected MenuBar(JFrame s) {
		super();
		superFrame = s;
		
		game = new JMenu("Game");
		help = new JMenu("Help");
		options = new JMenu("Options");
		newGame = new JMenu("New");
		onlineGame = new JMenu("Online Game");
		onlineGameHelp = new JMenu("Playing Online");
		quit = new JMenuItem("Quit");
		about = new JMenuItem("About this game");
		cardValues = new JMenuItem("Card Values");
		background = new JMenuItem("Change Background");
		changeName = new JMenuItem("Change Nick");
		localGame = new JMenuItem("Local Game");
		join = new JMenuItem("Connect to Server");
		create = new JMenuItem("Start a new Server");
		serverHelp = new JMenuItem("Creating a Server");
		clientHelp = new JMenuItem("Connecting to a Server");
		
		onlineGame.add(create);
		onlineGame.add(join);
		
		newGame.add(localGame);
		localGame.setEnabled(true);
		newGame.add(onlineGame);
		
		onlineGameHelp.add(serverHelp);
		onlineGameHelp.add(clientHelp);
		
		game.add(newGame);
		game.add(quit);
		help.add(onlineGameHelp);
		help.add(cardValues);
		help.add(about);
		options.add(changeName);
		options.add(background);
		
		add(game);
		add(options);
		add(help);
		
		game.setMnemonic('G');
		options.setMnemonic('O');
		help.setMnemonic('H');
		quit.setMnemonic('Q');
		
		
		quit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				System.exit(0);
			}
		});
		
		//Pops up the About Dialog
		about.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				JOptionPane.showMessageDialog(superFrame,"Truco! o Algo... Version 0.24 - March XX 2007\n" +
						"Created by Ale Ricatti in 2006\n" +
						"Developed by that same shameful person\n" +
						"Sourceforge project site http://sourceforge.net/projects/truco-o-algo\n" +
						"Web Site coming soon!","About this mess",JOptionPane.INFORMATION_MESSAGE);				
			}
		});
		
		//Pops up a Dialog with the values of the cards
		cardValues.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				JOptionPane.showMessageDialog(superFrame,"From strong to weak\n" +
						"Swords 1 (macho)\n" +
						"Clubs 1(hembra)\n" +
						"Swords 7\n" +
						"Gold 7\n" +
						"All the threes (3)\n" +
						"All the twos (2)\n" +
						"Cups and Gold 1\n" +
						"All the Kings (12)\n" +
						"All the Knights (11)\n" +
						"All the Jacks (10)\n" +
						"Cups and Clubs 7\n" +
						"All the sixes (6)\n" +
						"All the fives (5)\n" +
						"All the fours (4)","Card Values",JOptionPane.INFORMATION_MESSAGE);
			}
		});
		
		serverHelp.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				JOptionPane.showMessageDialog(superFrame,"Creating a server is quite easy.\n" +
						"All you have to do is select 'Start a New Server'\n" +
						"on the Game->New->Online Game menu,\n" +
						"a small dialog will appear asking you to select\n" +
						"a port for the server, generally, just clicking OK\n" +
						"with the default port(4444) selected should be all right,\n" +
						"but if you have some other program using that port you\n" +
						"will have to select another one.\n" +
						"If everything went right, the Chat Panel should say something\n" +
						"like Tell your friends to connect to XXX.XXX.XXX.XXX:XXXX\n" +
						"that's your IP and port number, the client needs that to connect\n" +
						"to you. If the IP address you got is 127.0.0.1 (home), it means you have\n" +
						"more than one network interface on your computer, what you'll have\n" +
						"to do is go to http://www.ip-adress.com/ , get your real IP,\n" +
						"and replace 127.0.0.1 with it, otherwise the client won't be\n" +
						"able to join your server.\n" +
						"One more thing, remember to give your IP only to people\n" +
						"you know and trust, it's not safe to give it to anyone.\n" +
						"Enjoy the game!","How to create a Server",JOptionPane.INFORMATION_MESSAGE);
			}
		});
		
		clientHelp.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				JOptionPane.showMessageDialog(superFrame,"In order to connect to a server you must\n" +
						"first know the IP address of the host and the port in which the\n" +
						"game server is listening, the creator of the server should give\n" +
						"you this information. Then select Game->New->Online Game->Connect to Server\n" +
						"A small input dialog will appear asking you to type in the address and port\n" +
						"of the server, just type the IP address followed by a colon (:) and then the port\n" +
						"number, no spaces in between, and click OK. Done! if you did everything right you\n" +
						"should be connected to the server in less than a second.","How to connect to a server",JOptionPane.INFORMATION_MESSAGE);
			}
		});
		
	}

}
